//app.js
var app = getApp()
App({
  onLaunch: function () {
    var that = this;
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    console.log('App Launch');
    wx.login({
      success: function (res) {
        if (res.code) {
          // console.log(111);
          // console.log(res.code);
          //发起网络请求
          wx.request({
            url: getApp().data.apiurl + '/index.php/index/index/getOpenid',
            data: { code: res.code },
            header: {
              'content-type': 'application/json'
            },
            success: function (ress) {
              console.log(ress.data.openid);
              that.globalData.openid = ress.data.openid
            }
          })
        }
        wx.getUserInfo({
          success: function (res) {
            that.globalData.userInfo = res.userInfo
            typeof cb == "function" && cb(that.globalData.userInfo)
            console.log(res.userInfo);
            //获取用户信息
            wx.request({
              url: getApp().data.apiurl + '/index.php/index/index/adduser',
              data: {
                unickname: res.userInfo.nickName,
                usex: res.userInfo.gender,
                uopenid: that.globalData.openid
              },
              header: {
                'content-type': 'application/json'
              },
              success: function (res) {
				  
              }
            })
          }
        })
      }
    });
  },
  // onShow: function () {
  //   console.log('App Show')
  // },
  globalData: {
    userInfo: null,
    openid: null,
    city:null
  },
  data: {
    // apiurl: 'http://www.ynspsc.com'
    apiurl:'https://hzp.zhongweixintong.com'
  },
  pointFloat:function(f)
  {
    var m = Math.pow(10, 1);
    return parseInt(f * m, 10) / m;
  }

})